import 'package:get/get.dart';
import '../../views/pages/home_page.dart';
import '../../views/pages/record_page.dart';
import '../../views/pages/history_page.dart';
import '../../views/pages/analysis_page.dart';
import '../../views/pages/settings_page.dart';
import '../../views/pages/record_detail_page.dart';
import '../../views/pages/splash_page.dart';
import '../../controllers/emotion_controller.dart';
import '../../controllers/analytics_controller.dart';
import '../../controllers/history_controller.dart';
import '../../controllers/settings_controller.dart';
import '../../controllers/record_detail_controller.dart';

/// 应用路由配置
/// Application route configuration
class AppRoutes {
  // 私有构造函数，防止实例化
  // Private constructor to prevent instantiation
  AppRoutes._();

  // ==================== 路由路径常量 Route Path Constants ====================
  
  /// 启动页路由
  /// Splash page route
  static const String splash = '/splash';
  
  /// 首页路由
  /// Home page route
  static const String home = '/home';
  
  /// 记录页面路由
  /// Record page route
  static const String record = '/record';
  
  /// 记录详情页面路由
  /// Record detail page route
  static const String recordDetail = '/record-detail';
  
  /// 历史页面路由
  /// History page route
  static const String history = '/history';
  
  /// 趋势分析页面路由
  /// Analytics page route
  static const String analytics = '/analytics';
  
  /// 设置页面路由
  /// Settings page route
  static const String settings = '/settings';
  
  // ==================== 初始路由 Initial Route ====================
  
  /// 应用初始路由
  /// Application initial route
  static const String initial = splash;
  
  // ==================== 路由页面配置 Route Pages Configuration ====================
  
  /// 获取所有路由页面配置
  /// Get all route pages configuration
  static List<GetPage> getPages() {
    return [
      // 启动页
      // Splash page
      GetPage(
        name: splash,
        page: () => const SplashPage(),
        transition: Transition.fadeIn,
        transitionDuration: const Duration(milliseconds: 300),
      ),
      
      // 首页
      // Home page
      GetPage(
        name: home,
        page: () => const HomePage(),
        binding: HomeBinding(),
        transition: Transition.fadeIn,
        transitionDuration: const Duration(milliseconds: 300),
      ),
      
      // 记录页面
      // Record page
      GetPage(
        name: record,
        page: () => const RecordPage(),
        binding: RecordBinding(),
        transition: Transition.rightToLeft,
        transitionDuration: const Duration(milliseconds: 300),
      ),
      
      // 记录详情页面
      // Record detail page
      GetPage(
        name: recordDetail,
        page: () => const RecordDetailPage(),
        binding: RecordDetailBinding(),
        transition: Transition.rightToLeft,
        transitionDuration: const Duration(milliseconds: 300),
      ),
      
      // 历史页面
      // History page
      GetPage(
        name: history,
        page: () => const HistoryPage(),
        binding: HistoryBinding(),
        transition: Transition.fadeIn,
        transitionDuration: const Duration(milliseconds: 300),
      ),
      
      // 趋势分析页面
      // Analytics page
      GetPage(
        name: analytics,
        page: () => const AnalysisPage(),
        binding: AnalyticsBinding(),
        transition: Transition.fadeIn,
        transitionDuration: const Duration(milliseconds: 300),
      ),
      
      // 设置页面
      // Settings page
      GetPage(
        name: settings,
        page: () => const SettingsPage(),
        binding: SettingsBinding(),
        transition: Transition.rightToLeft,
        transitionDuration: const Duration(milliseconds: 300),
      ),
    ];
  }
  
  // ==================== 导航方法 Navigation Methods ====================
  
  /// 跳转到首页
  /// Navigate to home page
  static void toHome() {
    Get.offAllNamed(home);
  }
  
  /// 跳转到记录页面
  /// Navigate to record page
  static void toRecord({String? emotionType, int? intensity}) {
    Get.toNamed(
      record,
      arguments: {
        'emotionType': emotionType,
        'intensity': intensity,
      },
    );
  }
  
  /// 跳转到记录详情页面
  /// Navigate to record detail page
  static void toRecordDetail(String recordId) {
    Get.toNamed(
      recordDetail,
      arguments: {'recordId': recordId},
    );
  }
  
  /// 跳转到历史页面
  /// Navigate to history page
  static void toHistory({DateTime? selectedDate}) {
    Get.toNamed(
      history,
      arguments: {'selectedDate': selectedDate},
    );
  }
  
  /// 跳转到趋势分析页面
  /// Navigate to analytics page
  static void toAnalytics({String? analysisType}) {
    Get.toNamed(
      analytics,
      arguments: {'analysisType': analysisType},
    );
  }
  
  /// 跳转到设置页面
  /// Navigate to settings page
  static void toSettings() {
    Get.toNamed(settings);
  }
  
  /// 返回上一页
  /// Go back to previous page
  static void back() {
    Get.back();
  }
  
  /// 返回到指定页面
  /// Go back to specific page
  static void backTo(String routeName) {
    Get.until((route) => route.settings.name == routeName);
  }
  
  /// 替换当前页面
  /// Replace current page
  static void replace(String routeName, {dynamic arguments}) {
    Get.offNamed(routeName, arguments: arguments);
  }
  
  /// 清除所有页面并跳转
  /// Clear all pages and navigate
  static void offAll(String routeName, {dynamic arguments}) {
    Get.offAllNamed(routeName, arguments: arguments);
  }
}

// ==================== 依赖绑定 Dependency Bindings ====================

/// 首页依赖绑定
/// Home page dependency binding
class HomeBinding extends Bindings {
  @override
  void dependencies() {
    // 注册首页需要的控制器
    // Register controllers needed for home page
    Get.lazyPut<EmotionController>(() => EmotionController());
  }
}

/// 记录页面依赖绑定
/// Record page dependency binding
class RecordBinding extends Bindings {
  @override
  void dependencies() {
    // 注册记录页面需要的控制器
    // Register controllers needed for record page
    Get.lazyPut<EmotionController>(() => EmotionController());
  }
}

/// 历史页面依赖绑定
/// History page dependency binding
class HistoryBinding extends Bindings {
  @override
  void dependencies() {
    // 注册历史页面需要的控制器
    // Register controllers needed for history page
    Get.lazyPut<HistoryController>(() => HistoryController());
    Get.lazyPut<EmotionController>(() => EmotionController());
  }
}

/// 趋势分析页面依赖绑定
/// Analytics page dependency binding
class AnalyticsBinding extends Bindings {
  @override
  void dependencies() {
    // 注册趋势分析页面需要的控制器
    // Register controllers needed for analytics page
    Get.lazyPut<AnalyticsController>(() => AnalyticsController());
    Get.lazyPut<EmotionController>(() => EmotionController());
  }
}

/// 设置页面依赖绑定
/// Settings page dependency binding
class SettingsBinding extends Bindings {
  @override
  void dependencies() {
    // 注册设置页面需要的控制器
    // Register controllers needed for settings page
    Get.lazyPut<SettingsController>(() => SettingsController());
  }
}

/// 记录详情页面依赖绑定
/// Record detail page dependency binding
class RecordDetailBinding extends Bindings {
  @override
  void dependencies() {
    // 注册记录详情页面需要的控制器
    // Register controllers needed for record detail page
    Get.lazyPut<RecordDetailController>(() => RecordDetailController());
  }
}